﻿#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

using llt = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int N;
string S;

int proc(){
    int cnt[27] = {0};
    for(auto ch : S){
        ++cnt[ch - 'A' + 1];
    }
    int ans = 0;
    for(int i=1;i<=26;++i)if(cnt[i]>=i)++ans;
    return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
    int nofkase = 1;
    cin >> nofkase;
    while(nofkase--){
        cin >> N >> S;
        cout << proc() << endl;
    }
    return 0;
}